package com.company.ljh;

import java.io.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class Main {
    public static void main(String[] args) {
        Stack stack = new Stack();
        ArrayList <String> list = new ArrayList<>();
        Iterator<String> iterator = list.iterator();

        int prices [] = new int[]{9,8,7,1,2};
            int fee = 3;
        int total = 0;
        int min = prices[0];
        int max = prices[0];
        for(int i =1;i<prices.length;i++){
            //如果上次max-min-2赚的钱足以让此次买股票的价格比上一次低，则可以购买
            if(prices[i] - (max - min - fee) < min){
                total+=max - min - fee;
                min = prices[i];
                max = prices[i];
            }if(prices[i]<min){
                min = Math.min(prices[i],min);
                max = min;
            }

        }

        System.out.println(total + (max - min - fee));
        PriorityQueue queue  = new PriorityQueue(3);
    }

}

